define(function(require, exports, module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	var AJAX = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
	var dgutil = undefined;

	using(["validatebox"],function(){
		$.extend($.fn.validatebox.defaults.rules, {
			vehicleLoadRules: {
				validator: function(value){
					return /^[0-9]+(\.[0-9]{2})?$/.test(value);
				},message: "只能为正整数,两位小数"
			},
			contactTelRules: {
				validator: function(value){
					return /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/.test(value);
				},message: "手机格式有误"
			}
		});
	});
	var config = {
			name:"运输车辆表",
			column:[[
                    {field:'id',title:'主键ID',width:100,align:'center',height:50,hidden:true},
                    
                    {field:'sectionId',title:'标段ID',width:100,align:'center',height:50,hidden:true},
                    
                    {field:'plateNumber',title:'车牌号',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'vehicleIdentity',title:'车辆标识',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'deviceNo',title:'设备MAC',width:100,align:'center',height:50,hidden:false},

				    {field:'contactPerson',title:'联系人',width:100,align:'center',height:50,hidden:false},

                    {field:'frdRemark',title:'RFID标签',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'vehicleLoad',title:'载重（吨）',width:100,align:'center',height:50,hidden:false},

                    {field:'contactTel',title:'联系电话',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'createTime',title:'添加时间',width:100,align:'center',height:50,hidden:false},
                    
                    {field:'updateUser',title:'最近更新人',width:100,align:'center',height:50,hidden:true},
                    
                    {field:'updateTime',title:'最近更新时间',width:100,align:'center',height:50,hidden:true},
                    ]]
	}
	
	var initpage = function(){
			dgutil = EUtil.ajaxDataGrid(datagridconfig);
		}
	var initFiledByForm = function(rows,id){
		var validate = true;
		if(typeof rows == "boolean"){
			validate = rows;
		}
	}

	var addDialogInit = function(url){
		$("#editdlg").dialog({
			title:config.name+"增加",
			href:url,
			onLoad:function(){
				initFiledByForm(false,'add');
		    },
			buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if($("#editform").form("validate")){
							var sectionId = sessionStorage.getItem('sectionId');
							if(sectionId == null || sectionId == undefined){
								sectionId = '0';
							}
							var obj = $("#editform").serializeJson();
							obj.sectionId = sectionId;
							AJAX.init().success(function(code,msg,data){
								$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
								dgutil.pager();
								$("#editdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert("系统提示", msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+"/dcs/sys/transportVehicle/saveSysTransportVehicle.htm",JSON.stringify(obj));
						}
					});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#editdlg').dialog('close');
				}
			}]
		});
		$("#editdlg").dialog("open");
	}
	var updDialogInit = function(url,row){
		$("#editdlg").dialog({
			iconCls: 'icon-save',
			title:config.name+'修改',
			href:url,
			onLoad:function(){
				initFiledByForm(row,'upd');
				$("#editform").form("load",row);
		    },
			buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if($("#editform").form("validate")){
							var sectionId = sessionStorage.getItem('sectionId');
							if(sectionId == null || sectionId == undefined){
								sectionId = '0';
							}
							var obj = $("#editform").serializeJson();
							obj.sectionId = sectionId;
							AJAX.init().success(function(code,msg,data){
								$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
								dgutil.pager();
								$("#editdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert("系统提示", msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+'/dcs/sys/transportVehicle/updateSysTransportVehicle.htm',JSON.stringify(obj));
						}
					});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#editdlg').dialog('close');
				}
			}]
		});
		$("#editdlg").dialog("open");
	}
	var delInit = function(url,rows){
		var checks = [];
		for(var key in rows){
			var id = '' +rows[key].id;
			checks.push(id);
		}
		EUtil.ajaxHandler(url,{checkeds:checks.join(",")},function(){
			dgutil.delRow(rows);
		});
	}
	module.exports = {
			trans:function(){
				var buttons ={ 
						title:{
							_class:"",
							text:"运输车辆表列表"
						},
						btn:[
						     {
						    	 iconCls: 'icon-search',
						    	 url:'/dcs/sys/transportVehicle/querySysTransportVehicleByPage.htm',
						    	 text:"查询",
						    	 addClass:'l-btn-display',
						    	 handler: function(){dgutil.pager(1);}
						     },
						     {
						    	 iconCls: 'icon-add',
						    	 addClass:'l-btn-display',
						    	 text:"添加",
						    	 url:'/view/dcs/sys/transportVehicle/systransportvehicleadd',
						    	 handler: addDialogInit
						     },
						     {
						    	 iconCls: 'icon-edit',
						    	 url:'/view/dcs/sys/transportVehicle/systransportvehicleupd',
						    	 text:"修改",
						    	 addClass:'l-btn-display',
						    	 needRow:true,
						    	 handler: updDialogInit
						     },
						     {
						    	 iconCls: 'icon-remove',
						    	 url:'/dcs/sys/transportVehicle/deleteSysTransportVehicle.htm',
						    	 text:"删除",
						    	 addClass:'l-btn-display',
						    	 needRows:true,
						    	 isCheck:true,
						    	 handler: delInit
						     }
						     ]};
				datagridconfig = {
						fitColumns:true,
						singleSelect:false,
						striped:true,
						autoRowHeight:false,
						fit: true,
						toolbar:buttons,
						columns:config.column,
						eid:"dg",
						url:BASEPATH+'/dcs/sys/transportVehicle/querySysTransportVehicleByPage.htm',
						args:"searchform"
				};
				
				using(["parser","dialog","datagrid" ],function(){
					initpage();
				});
			}
	}
});
